package br.com.pizzaria.modelo;

import java.util.List;

import org.hibernate.Session;
import br.com.caelum.vraptor.ioc.Component;

@Component
public class PizzariaDAO {

	private final Session session;

	public PizzariaDAO(Session session) {
		this.session = session;
	}

	@SuppressWarnings("unchecked")
	public List<Pizzaria> lista() {
		return (List<Pizzaria>) session.createQuery("FROM Pizzaria").list();
	}

	public Pizzaria autenticar(String emailPizzaria, String senha) {
		
    	System.out.println("PizzariaDAO email: " + emailPizzaria);
    	System.out.println("PizzariaDAO senha: " + senha);
    	
		return (Pizzaria) session
				.createQuery(
						"FROM Pizzaria WHERE emailPizzaria = :emailPizzaria AND senha = :senha")
				.setParameter("emailPizzaria", emailPizzaria).setParameter("senha", senha)
				.uniqueResult();

	}
	
	public void salvar(Pizzaria pizzaria) {
		session.save(pizzaria);
	}
}